package com.muniuliuma.basecontrol;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;

public class BaseListActivity extends ListActivity implements ActivityInterface {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MenuControl.sCurrentActivity = this;
		ActivityStack.getInstance().pushActivity(this);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		MenuControl.sCurrentActivity = this;
		unlockScreen();
	}

	@Override
	public void finish() {
		super.finish();
		ActivityStack.getInstance().popActivity(this);
	}
	
	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {
		if (MenuControl.isWinscapeLocked()) {
			return true;
		} else {
			return super.dispatchKeyEvent(event);
		}
	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		if (MenuControl.isWinscapeLocked()) {
			return true;
		} else {
			return super.dispatchTouchEvent(ev);
		}
	}

	@Override
	public boolean dispatchTrackballEvent(MotionEvent ev) {
		if (MenuControl.isWinscapeLocked()) {
			return true;
		} else {
			return super.dispatchTrackballEvent(ev);
		}
	}
	
	public void startActivity(Class<? extends Activity> cls) {
		MenuControl.changeWinscape(this, cls);
	}

	public void backActivity() {
		MenuControl.backward(this);
	}
	
	public void lockScreen() {
		MenuControl.lockWinscape(true);
	}

	public void unlockScreen() {
		MenuControl.lockWinscape(false);
	}
	
	public boolean isWinscapeLocked(){
		return MenuControl.isWinscapeLocked();
	}


}
